package org.json;

import org.junit.Test;

import java.util.Iterator;
import java.util.List;

import static java.util.Arrays.*;
import static org.json.JsonObjectifier.*;
import static org.junit.Assert.*;

public class JsonObjectifierTest {

    @Test
    public void canIterateThroughJsonArrays() throws Exception {
        Iterator iterator = iterable(new JSONArray()
                .put(1.0)
                .put(2.0))
                .iterator();

        assertTrue(iterator.hasNext());
        assertEquals(1.0, iterator.next());
        assertTrue(iterator.hasNext());
        assertEquals(2.0, iterator.next());
        assertFalse(iterator.hasNext());
    }

    @Test
    public void testCanTestEqualityOfListsContainingJsonObjectsByWrappingThemInJsonFriendlyLists() throws Exception {
        List<Object> underlyingOne = asList(new JSONObject("{holder: {contents: 7.1}}"), 7);
        List<Object> underlyingTwo = asList(new JSONObject("{holder: {contents: 7.1}}"), 7);

        assertFalse(underlyingOne.equals(underlyingTwo));
        assertEquals(jsonEquable(underlyingOne), jsonEquable(underlyingTwo));
    }
}
